package util;
import org.apache.commons.codec.digest.DigestUtils;

import java.util.UUID;

public class MD5Utils {
    /**
     * 给你的密码加点盐，并且MD5
     * @param password
     * @param salt
     * @return
     */
    public static String passwordAddSalt(String password, String salt) {
        int plen = password.length();
        String str = salt.substring(15,16)+password.substring(plen/2)+salt.substring(0,4)+password.substring(0,plen/2)+salt.substring(6,9);
        return DigestUtils.md5Hex(DigestUtils.md5Hex(str));
    }

    /**
     * 生成随机盐值
     * @return
     */
    public static String createSalt(){
        String uuid = UUID.randomUUID().toString();
        uuid =uuid.replaceAll("-","");
        return uuid;
    }
    public static String MD5(String pp){
        return DigestUtils.md5Hex(pp);
    }
    public static void main(String[] args) {
        String sale = createSalt();
        System.out.println(sale);
        System.out.println(passwordAddSalt("666666",sale));
    }

}